<?php
require_once('../../pers/inc.config.php');
require_once(RGL_FS_WEB_ROOT."/app/_inc/inc.set1.php");
require_once(RGL_FS_WEB_ROOT."/app/_inc/class.rglSession.php");

if (!isset($isPopUp)) $isPopUp = false;
if (!isset($isReloadable)) $isReloadable = false;
ini_set("display_error", 1);
error_reporting(E_ALL);
// configura il gestore dell'errore definito dall'utente
$oldErrorHandler = set_error_handler("rgl_error_handler");

//Disattiva il caching della pagina
if (headers_sent()) {
	trigger_error(_t("inviati headers prima di checkSession"),E_USER_ERROR);
}

if (reqVar('xsn')=='') {
	rglErrSess(_t("sessione non identificata (1)"));
	exit();
}

session_start();

$ax = explode('.',reqVar('xsn'));
$subSess = $ax[0];
if (!isset($ax[1])) {
	if (!$isPopUp) {
		rglErrSess(_t("sessione non identificata (2) - %s",reqVar('xsn')));
		exit();
	}
	$pageSeq = 0;
} else {
	$pageSeq = intval($ax[1]);
}

$sessObjKey = RGL_SESS_OBJ_PREF.$subSess;
if(!isset($_SESSION[$sessObjKey])){
	rglErrSess(_t("sessione non identificata (3) - %s",$_REQUEST['xsn']));
	exit();
}
if(!is_object($_SESSION[$sessObjKey])){
	rglErrSess(_t("sessione non identificata (4) - %s",$_REQUEST['xsn']));
	exit();
}
$objSess = $_SESSION[$sessObjKey];
define('XSN',"$subSess.".$objSess->pageSequence);
$sXSNQS = "xsn=".urlencode(XSN);
$objSess->mcrTmStrt = microtime(true);
// aggiorna tabella session
$sTimeNow = date('Y-m-d H:i:s');

$tit1=_t(RGL_TITOLO1);

$nWidth = 400;
$sStyle = "style='padding-top:100px;'";
?>
<HTML>
<HEAD>
<META Name="expires" CONTENT= "Mon, 1 Jan 2000 00:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="content-language" content="it">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=windows-1251">
<TITLE><?=$tit1?> - log-out</TITLE>
<SCRIPT LANGUAGE="JavaScript">
</SCRIPT>
<link rel="shortcut icon" href='<?=RGL_URL_ROOT?>/app/_img/rgl.ico' type="image/x-icon" />
<LINK rel="stylesheet" href="<?=RGL_URL_ROOT?>/app/_com/css.stilePar.php" type="text/css">
</HEAD>
<body  onLoad="" <?=$sStyle?>>
<table cellpadding="5" cellspacing="2" width='<?=$nWidth?>' align='center'>
<tr>
	<td class="lab1" style='font-weight:bold;' colspan='2'>
		<?=$tit1?>
	</td>
</tr>
<?
if ($objSess->login == '@@logout@@') {
?>
<tr>
	<td class="txt1" style='font-weight:bold;text-align:center' colspan='2'>
		Sessione chiusa
	</td>
</tr>
<tr>
	<td class="cmd1" align='right' colspan='2'>
		<a href='#' onClick='window.close();' class='cmd1'>chiudi</a>
	</td>
</tr>

<?
	echo "</table>\n</body>\n</HTML>";
	exit();
}
?>
<tr>
	<td class="lab1" style='font-weight:bold;text-align:center' colspan='2'>
		<?=_t('Log-out eseguito correttamente')?>
	</td>
</tr>
<tr>
	<td class="lab1" style='font-weight:bold;' width='20%'>
		<?=_t('Utente')?>: 
	</td>
	<td class="txt1" style='font-weight:bold;' width='80%'>
		<?=$objSess->nome;?>
	</td>
</tr>
<tr>
	<td class="lab1" style='font-weight:bold;' width='20%'>
		log-in: 
	</td>
	<td class="txt1" style='font-weight:bold;' width='80%'>
		<?=date("d/m/y H:i:s",$objSess->loginTime);?>
	</td>
</tr>
<tr>
	<td class="lab1" style='font-weight:bold;' width='20%'>
		log-out: 
	</td>
	<td class="txt1" style='font-weight:bold;' width='80%'>
		<?=date("d/m/y H:i:s");?>
	</td>
</tr>
<tr>
	<td class="lab1" style='font-weight:bold;' width='20%'>
		<?=_t('Durata')?>: 
	</td>
	<td class="txt1" style='font-weight:bold;' width='80%'>
		<?
		$dur=time()-$objSess->loginTime;
		$sec=$dur%60;
		$min=(($dur-$sec)/60)%60;
		$ore=($dur-$sec-$min*60)/3600;
		echo $ore.":".str_pad($min,2,'0',STR_PAD_LEFT).":".str_pad($sec,2,'0',STR_PAD_LEFT);
		?>
	</td>
</tr>
</table>
<table cellpadding="5" cellspacing="2" width='<?=$nWidth?>' align='center'>
	<tr>
		<td class="cmd1" align='left'>
			<a href='login.php' class='cmd1'>log-in</a>
		</td>
		<td class="cmd1" align='right'>
			<a href='#' onClick='window.close();' class='cmd1'><?=_t('chiudi')?></a>
		</td>
	</tr>
</table>
</body>
</HTML>
<?
if ($objSess->login != '@@logout@@') {
	$_SESSION[RGL_SESS_OBJ_PREF.$subSess] = new rglSession();
}
exit();
?>